package com.yyds.oneservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yyds.oneservice.pojo.CmsSubject;
import com.yyds.oneservice.mapper.CmsSubjectMapper;
import com.yyds.oneservice.pojo.UserMember;
import com.yyds.oneservice.service.ICmsSubjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yyds.oneservice.vo.CmsSubjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 专题表 服务实现类
 * </p>
 *
 * @author lxy
 * @since 2022-12-12
 */
@Service
public class CmsSubjectServiceImpl extends ServiceImpl<CmsSubjectMapper, CmsSubject> implements ICmsSubjectService {
    @Autowired
    private CmsSubjectMapper cmsSubjectMapper;
//    public List<CmsSubject> findByM() {
//        QueryWrapper<CmsSubject> queryWrapper = new QueryWrapper<>();
//        queryWrapper.like("category_name","%"+"萌宠"+"%");
//        List<CmsSubject> cmsSubjects = cmsSubjectMapper.selectList(queryWrapper);
//        return cmsSubjects;
//    }
//
//    public List<CmsSubject> findBycmsName(String cmsName) {
//        QueryWrapper<CmsSubject> queryWrapper = new QueryWrapper<>();
//        queryWrapper.like("category_name","%"+cmsName+"%");
//        List<CmsSubject> cmsSubjects = cmsSubjectMapper.selectList(queryWrapper);
//        return cmsSubjects;
//    }
    public List<CmsSubjectVo> findByM() {
        List<CmsSubjectVo> cmsSubjects=cmsSubjectMapper.findByM();
        return cmsSubjects;
    }

    public List<CmsSubjectVo> findBycmsName(String cmsName) {
            List<CmsSubjectVo> collect = cmsSubjectMapper
                    .findBycmsName()
                    .stream()
                    .filter(cmsSubjectVo -> {
                        return cmsSubjectVo.getCategoryName().startsWith(cmsName);
                    })
                    .collect(Collectors.toList());
            return collect;
    }
}
